package com.ayh.campusfun.controller.api.v1;

import cn.hutool.core.util.RandomUtil;
import com.ayh.campusfun.common.exception.http.ForbiddenException;
import com.ayh.campusfun.common.exception.http.NotFoundException;
import com.ayh.campusfun.service.CaptchaService;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import org.apache.axis.encoding.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ayh
 * @create 2021/3/23 0023 11:04
 * 验证码控制器
 */

@RestController
@RequestMapping("captcha")
public class CaptchaController {
    @Autowired
    private CaptchaService captchaService;

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    @GetMapping(value = "/getCaptcha",produces = "application/json")
    public String getCaptcha (){
       return captchaService.getCaptcha();
    }

    @GetMapping(value = "/refreshCaptcha",produces = "application/json")
    public String refreshCaptcha (String captchaKey){
        redisTemplate.delete(captchaKey);
       return captchaService.getCaptcha();
    }
}
